<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加机构信息</title>
<link rel="stylesheet" type="text/css" href="css/css.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/province_city.js"></script>
 <style>
	#infotable td{
		font-size: 16px;
		border:none !important;
	}
	.bbD .td{
		font-size: 16px;
		text-aign:right;
	}
	.text2{
		font-size: 16px;
		text-aign:right;
		width: 300px;
	}
    .button{
			margin-top:20px;
			font-size: 16px;
			width: 135px;
			height: 40px;
			border-radius:20px;
			border: 1px solid #ccc;
			margin-left: 35px;
			color: #fff;
			background-color: #47a4e1;
	}
	td{border:0px}
	.bor {
    border: 0px solid #ccc;
    }
</style>
<script type="text/javascript">

	/*  省市级联  */
	function initProvince(){  
		document.all.selProvince.length = 0 ;   
		for(i=0; i<provinceArray.length; i++){  
		   document.all.selProvince.options[i] = new Option(provinceArray[i],provinceArray[i]);  
		}  
		getCity(document.all.selProvince.options[0].value)  
		}  
		  
	function getCity(currProvince){  
		  //当前 所选择 的 省  
		  var currProvincecurrProvince = currProvince;  
		  var i,j,k;  
		  //清空 城市 下拉选单  
		  document.all.selCity.length = 0 ;   
		  for (i = 0 ;i <cityArray.length;i++)  
		    {     
		       //得到 当前省 在 城市数组中的位置  
		       if(cityArray[i][0]==currProvince)  
		          {     
		            //得到 当前省 所辖制的 地市  
		            tmpcityArray = cityArray[i][1].split("|")  
		            for(j=0;j<tmpcityArray.length;j++)  
		            {  
		              //填充 城市 下拉选单  
		               document.all.selCity.options[document.all.selCity.length] = new Option(tmpcityArray[j],tmpcityArray[j]);   
		             }  
		          }   
		    }   
		}  


	/* 验证机构是否存在  */
	 
		function checkOrganame(){
			$("#spaninfo").html("");
		 	var orgname=$("#orgname").val();
		 	var reg=/^(?=.*?[\u4E00-\u9FA5])[\dA-Za-z\u4E00-\u9FA5]+(?=.*?[\u4E00-\u9FA5])/;
			if(orgname==null || ""==orgname){
				$("#spaninfo").html("机构名称不能为空").css({color:"red"});
				return false;
			}else if(!reg.test(orgname)){
				$("#spaninfo").html("机构名称不能全是数字或字母，必须要有汉字").css({color:"red"});
				return false;
			}else{
				$.ajax({
					url:"organization_validate.do",
					type:"POST",
					dataType:"text",
					data:"orgname="+orgname,
					success:function(result){
						if(result=="true"){
							$("#spaninfo").html("对不起,此机构已存在!").css({color:"red"});
							 return false; 
						}
						if(result=="false"){
							//$("#spaninfo").html("机构名称可以使用").css({color:"green"});
							return true;
						}
					}
				});  
			}
			return true;
		}
	
		
	
	/* 判断手机号码是否存在联系人表中 */
		function checkPhone(){
			$("#phoneinfo").html("");
			var phone=$("#phone").val();
			var reg = /^\d+$/;
			if(phone==null || ""==phone){
				$("#phoneinfo").html("手机号不能为空!").css({color:"red"});
				return false;
			}else if(!reg.test(phone)){
				$("#phoneinfo").html("手机必须是数字").css({color:"red"});
				return false;
			}else if(phone.length!=11){
				$("#phoneinfo").html("手机必须是11位数字").css({color:"red"});
				return false;
			}else{
				$.ajax({
				url:"phonevalidate.do",
				type:"POST",
				dataType:"json",
				data:"phone="+phone,
				success:function(result){
					if(result.res=="false"){
						$("#p").html("不存在此联系人，点此添加").css({color:"red"});
						$("#ename").val("");
						return false;
					}
					if(result.res=="true"){
						$("#cid").val(result.id);
						$("#ename").val(result.ename);
						//$("#phoneinfo").html("此联系人可用").css({color:"green"});
						return true;
					}
				}
			}); 
		}
		return true;
	}
		
	
	/* 机构地址不能为空验证 */
	function checkAddress(){
		$("#addressinfo").html("");
		var address=$("#address").val();
		var reg=/^(?=.*?[\u4E00-\u9FA5])[\dA-Za-z\u4E00-\u9FA5]+(?=.*?[\u4E00-\u9FA5])/;
		if(address==null ||""==address){
			$("#addressinfo").html("机构地址不能为空").css({color:"red"});
			return false;
		}else if(!reg.test(address)){
			$("#addressinfo").html("地址不能全是数字或字母，必须要有汉字").css({color:"red"});
			return false;
		}
		return true;
		
	}
	
	/* 验证邮政编码 */
	function checkCode(){
		$("#codeinfo").html("");
		var code=$("#code").val();
		var reg = /^\d+$/;
		if(code==null ||""==code){
			$("#codeinfo").html("邮政编码不能为空！").css({color:"red"});
			return false;
		}else if(!reg.test(code)){
			$("#codeinfo").html("邮政编码必须是数字").css({color:"red"});
			return false;
		}else if(code.length!=6){
			$("#codeinfo").html("邮政编码必须是6位数字").css({color:"red"});
			return false;
		}else{
			//$("#codeinfo").html("邮政编码可用").css({color:"green"});
			return true;
		}
	}
		
		/* 网址的验证 */
		function checkNet(){
			$("#netinfo").html("");
			var net = $("#net").val();
			var reg= /^(http(s)?:\/\/)?(www\.)?[\w-]+\.\w{2,4}(\/)?$/;
			if(net==null ||""==net){
				$("#netinfo").html("网址不能为空").css({color:"red"});
				return false;
			}else if(!reg.test(net)){
				$("#netinfo").html("网址不符合").css({color:"red"});
				return false;
			}else{
				//$("#netinfo").html("网址符合条件").css({color:"green"});
				return true;
			}	
		}
		
		function isExsit(){
			if(checkOrganame() && checkPhone() && checkAddress() && checkCode() && checkNet()){
				return true;
			}else{
				return false;
			}
		}
		
		
	

</script>

</head>
<body onload="initProvince()">
	<div id="pageAll">
		<div class="pageTop">
			<div class="page">
				<img src="img/coin02.png" /><span><a href="main.html">首页</a>&nbsp;-&nbsp;
				<a href="infomanage.do">机构管理</a>&nbsp;-</span>&nbsp;添加机构信息
			</div>
		</div>
		<div class="page ">
			<!-- 上传广告页面样式 -->
			<div class="banneradd bor">
				<form action="addOrganization.do" method="post" onsubmit="return isExsit()">
				<div class="baTopNo">
					<span>添加机构信息</span>
					<hr>
				</div>
				<div class="baBody" >
					<table calss="infotable">	
						<tr class="bbD"  >
							<td class="td">机构名称：</td>
							<td >
								<input type="text" class="input3" name="name" id="orgname" onblur="checkOrganame()" />
							</td>
							<td><span name="spaninfo" id="spaninfo"></span></td>				
						</tr>
						<tr class="bbD">
							<td class="td">机构地址：</td><td><input type="text" class="input3" id="address" name="address" onblur="checkAddress()" /></td>
							<td><span name="addressinfo" id="addressinfo"></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">联系人手机号：</td><td><input type="text" class="input3" name="phone" id="phone" onblur="checkPhone()"/></td>
							<td><span name="phoneinfo" id="phoneinfo"></span><a id="p" href="getcontactmanageadd.do"></a></td>
							<td class="td" style="display:none">联系人id：</td><td style="display:none"><input type="text" class="input3" name="cid" id="cid" /></td>
						</tr>
						<tr class="bbD" >
							<td class="td">联系人姓名：</td><td><input type="text" class="input3" name="ename" id="ename" disabled="disabled" /></td>
						</tr>
						<tr class="bbD">
							<td class="td">省份：</td>
							<td>
								<!-- <input type="text" class="input3" name="province" /> -->
								 <select name="province" id="selProvince" class="input3" onChange = "getCity(this.options[this.selectedIndex].value)">  
       							 </select>  
							</td>
						</tr>
						 <tr class="bbD">
							<td class="td">地级市/区：</td>
							<td>
								<!-- <input type="text" class="input3" name="city" /> -->
								<select name="city" id="selCity" class="input3">  
						            <option>北京</option>  
						        </select>
							</td>
						</tr> 
						<tr class="bbD">
							<td class="td">邮编：</td><td><input class="input3" type="text" name="code" id="code" onblur="checkCode()"/></td>
							<td><span name="codeinfo" id="codeinfo"></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">机构网址：</td><td><input class="input3"type="text" name="net" id="net" onblur="checkNet()"/></td>
							<td><span name="netinfo" id="netinfo"></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">机构类别：</td>
							<td>
								<select class="input3" name="type">
									<option value="1">政府</option>
									<option value="2">学校</option>
									<option value="3">企业</option>
									<option value="4">其他</option>
								</select>
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">重要级别：</td>
							<td>
								<select class="input3" name="vip">
									<option value="1">一般</option>
									<option value="2">重要</option>
									<option value="3">非常重要</option>
								</select>
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">审核状态：</td>
							<td>
								<select class="input3" name="checkstate">
									<option value="0">未审核</option>
									<option value="1">已审核</option>	
								</select>
							</td>
						</tr>
						
						<tr class="bbD">
							<td class="td">备注信息：</td>
							<td class="btext2">
								<textarea class="text2" name="remark"></textarea>
							</td>
						</tr>
					</table>	
						<input class="button" type="submit" value="添加" id="input3" />
						<input class="button" type="reset" value="重置" id="input3" />
				</div>
				</form>
			</div>
			<!-- 上传广告页面样式end -->
		</div>
	</div>
</body>

</html>